#include "start.h"
#include "gamescreen.h"
#include <QVBoxLayout>
#include <QPainter>

StartScreen::StartScreen(QWidget *parent) : QWidget(parent)
{
    setFixedSize(1094, 656);
    setupUI();
}

StartScreen::~StartScreen()
{
}

void StartScreen::setupUI()
{
    // 加载背景图片
    background.load(":/new/prefix1/image/background.jpg");

    // 设置标题
    titleLabel = new QLabel("下北泽野槌蛇", this);
    titleLabel->setAlignment(Qt::AlignCenter);
    QFont titleFont("Arial", 48, QFont::Bold);
    titleLabel->setFont(titleFont);
    titleLabel->setStyleSheet("color: pink;");

    // 设置开始按钮
    startButton = new QPushButton(this);
    startButton->setIcon(QIcon(":/new/prefix1/image/start_btn.png"));
    startButton->setIconSize(QSize(200, 100));
    startButton->setFixedSize(200, 100);
    startButton->setFlat(true);
    startButton->setStyleSheet("background-color: transparent;");

    // 布局
    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addStretch();
    layout->addWidget(titleLabel, 0, Qt::AlignCenter);
    layout->addSpacing(50);
    layout->addWidget(startButton, 0, Qt::AlignCenter);
    layout->addStretch();

    // 连接信号槽
    connect(startButton, &QPushButton::clicked, this, &StartScreen::startGame);
}

void StartScreen::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    painter.drawPixmap(0, 0, width(), height(), background);
}

void StartScreen::startGame()
{
    GameScreen *gameScreen = new GameScreen();
    gameScreen->show();
    this->close();
}
